home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_53649.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  27 lines

  1. -- card: 53649 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. MACRO SUBSTITUTION WITH PARAMETERS
  11.  
  12. Macros may be defined using parameters as well.  In this case the text passed as an        "argument" is placed into the replacement text everywhere the parameter appears:
  13.  
  14.     # define        SQUARE(x)      x * x                 /* don't use this version! */
  15.                   .
  16.                   .
  17.         f_array[i] = SQUARE(f_array[i]);
  18.  
  19. After preprocessing, the "call" to the SQUARE() macro expands to:
  20.  
  21.         f_array[i] = f_array[i] * f_array[i];
  22.  
  23. However, there is a serious deficiency with the SQUARE() macro defined above.  An expression like  'c = 1./SQUARE(a + b)'  expands to  'c = 1./a + b * a + b'.  Due to the arithmetic precedence rules, this does not produce the desired result.  The preprocessor performs text substitution without regard for rules of C syntax.  The
  24.  
  25. -- part contents for background part 7
  26. ----- text -----
  27. 172